﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hi_Baidu.Packet.InPacket.TalkInPacket.Hole
{
        class TestHolePacket  : TalkMessageInPackage
    {
        public TestHolePacket(TalkMessageInPackage inpackage)
            : base(inpackage)
        {
        }

        public override void InitPackage()
        {
            int Offset = 0;
            byte[] UsernameLength = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, UsernameLength, 0, 4);
            Offset += 4;
            byte[] Username = new byte[BitConverter.ToInt32(UsernameLength, 0)];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, Username, 0, Username.Length);
            Offset += Username.Length;
            byte[] HolePort = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, HolePort, 0, 4);
            Offset += 4;
            byte[] DigType = new byte[4];
            Array.ConstrainedCopy(this.Body["HEAD"], Offset, DigType, 0, 4);
            Offset += 4;

            this.DIC_CONTENT.Add("USERNAME", Username);
            this.DIC_CONTENT.Add("HOLEPORT", HolePort);
            this.DIC_CONTENT.Add("DIGTYPE", DigType);
        }

        /// <summary>
        ///     得到打洞的端口
        /// </summary>
        /// <returns>
        ///     返回要打洞的端口号
        /// </returns>
        public int GetHolePort()
        {
            return BitConverter.ToInt32(this.DIC_CONTENT["HOLEPORT"], 0);
        }

        /// <summary>
        ///     得到打洞类型
        /// </summary>
        /// <returns>
        ///     返回打洞类型
        /// </returns>
        public byte[] GetDigType()
        {
            return this.DIC_CONTENT["DIGTYPE"];
        }
    }
}
